<?
include("../lib/config.php");
$nik 	= $HTTP_GET_VARS['nik'];
$op		= $HTTP_GET_VARS['op'];

///*
$sqlcek	= mssql_query("SELECT * FROM KaryawanStatus WHERE NIK='$nik'",$conn);
$numcek	= mssql_num_rows($sqlcek);
//*/
if($numcek > 0){
	$Faction = "../lib/update.php";
	$Vbutton = "Update";
	$query	= mssql_query("SELECT CONVERT(CHAR(12), tmt_jab, 103) tamat_jabatan, CONVERT(CHAR(12), tmt_gol, 103) tamat_golongan, CONVERT(CHAR(12), tgl_masuk, 103) TglMasuk, CONVERT(CHAR(12), tgl_keluar, 103) TglKeluar, CONVERT(CHAR(12), tgl_nikah, 103) TglNikah,* FROM KaryawanStatus WHERE NIK='$nik' ",$conn);
	$row	= mssql_fetch_array($query);
	// get data from karir ptsi
	$skarptsi = mssql_query("SELECT * FROM VKarirPtsi WHERE NIK='$nik' ORDER BY seqno DESC",$conn);
	$rkarptsi = mssql_fetch_array($skarptsi);
}
else{
	$skarptsi = mssql_query("SELECT * FROM VKarirPtsi WHERE NIK='$nik' ORDER BY seqno DESC",$conn);
	$rkarptsi = mssql_fetch_array($skarptsi);

	$Faction = "../lib/save.php";
	$Vbutton = "Save";
}

include("../header.php");
?>
<script type="text/javascript">
	function LoadFocus(){
		document.forms[0].elements[0].focus();
	}
	
	MaskInput = function(f, m){
	function mask(e){
		var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
			rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
		function accept(c, rule){
			for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
				if(r & i && patterns[i].test(c))
					break;
				return i <= r || c == rule;
		}
		var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
		(!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
			r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
			: (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
			r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
	}
	for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
		addEvent(f, i, mask);
};

	function Validate(){
		if(document.FEmployee.nik.value == "")
		{
			alert("Field : NIK tidak boleh kosong ...");
			document.FEmployee.nik.focus();
			return false;
		}

		if(document.FEmployee.status_karyawan.value == "")
		{
			alert("Field : Status Karyawan tidak boleh kosong ...");
			document.FEmployee.status_karyawan.focus();
			return false;
		}
//*/		
		if(document.FEmployee.status_kerja.value == "")
		{
			alert("Field : Status Kerja tidak boleh kosong ...");
			document.FEmployee.status_kerja.focus();
			return false;
		}
///*
		//if(document.FEmployee.cara_kerja.value == "")
		//{
		//	alert("Field : Cara Kerja tidak boleh kosong ...");
		//	document.FEmployee.cara_kerja.focus();
		//	return false;
		//}

		if(document.FEmployee.jabatan.value == "")
		{
			alert("Field : Jabatan tidak boleh kosong ...");
			document.FEmployee.jabatan.focus();
			return false;
		}
/*
		if(document.FEmployee.tamat_jabatan.value == "")
		{
			alert("Field : Selesai Jabatan tidak boleh kosong ...");
			document.FEmployee.tamat_jabatan.focus();
			return false;
		}
*/
		if(document.FEmployee.golongan.value == "")
		{
			alert("Field : Golongan tidak boleh kosong ...");
			document.FEmployee.golongan.focus();
			return false;
		}
/*
		if(document.FEmployee.tamat_golongan.value == "")
		{
			alert("Field : Selesai Golongan tidak boleh kosong ...");
			document.FEmployee.tamat_golongan.focus();
			return false;
		}
*/
		if(document.FEmployee.fungsi.value == "")
		{
			alert("Field : Fungsi tidak boleh kosong ...");
			document.FEmployee.fungsi.focus();
			return false;
		}

		if(document.FEmployee.kode_so.value == "")
		{
			alert("Field : Unit Kerja tidak boleh kosong ...");
			document.FEmployee.kode_so.focus();
			return false;
		}
//*/
		if(document.FEmployee.tgl_masuk.value == "")
		{
			alert("Field : Tanggal Masuk tidak boleh kosong ...");
			document.FEmployee.tgl_masuk.focus();
			return false;
		}

		if(document.FEmployee.tgl_keluar.value == "")
		{
			alert("Field : Tanggal Keluar tidak boleh kosong ...");
			document.FEmployee.tgl_keluar.focus();
			return false;
		}

		if(document.FEmployee.tgl_nikah.value == "")
		{
			alert("Field : Tanggal Nikah tidak boleh kosong ...");
			document.FEmployee.tgl_nikah.focus();
			return false;
		}

		document.FEmployee.submit();
		
	}
</script>
</head>

<form name="FEmployee" method="post" action="<?=$Faction?>">
<table width="100%">
 <tr>
  <td colspan="2">
	<table width="100%">
	<tr>
	 <td colspan="2" class="line_bottom">&nbsp;<b>Status Karyawan</b></td>
	</tr>
	<tr>
	 <tr>
	  <td>&nbsp;</td>
	 <td align="right">
	 <a href="../lib/detailemp.php?show=status_karyawan&amp;nik=<?=$nik?>"><b>Status Karyawan</b></a> &raquo; 
	 <a href="../lib/detailemp.php?show=pribadi&amp;nik=<?=$nik?>">Data Pribadi</a> &raquo; 
	 <a href="../lib/detailemp.php?show=data_umum&amp;nik=<?=$nik?>">Data Umum</a> &raquo; 
	 <a href="../lib/detailemp.php?show=pendidikan&amp;nik=<?=$nik?>">Pendidikan</a> &raquo; 
	 <a href="../lib/detailemp.php?show=kecakapan&amp;nik=<?=$nik?>">Kecakapan</a> &raquo; 
	 <a href="../lib/detailemp.php?show=keluarga&amp;nik=<?=$nik?>">Keluarga</a> &raquo; 
	 <a href="../lib/detailemp.php?show=karir&amp;nik=<?=$nik?>">Pengalaman</a> &raquo; 
	 <a href="../lib/detailemp.php?show=organisasi&amp;nik=<?=$nik?>">Organisasi</a> 
	 </td>
	 </tr>
	</table>
  </td>
 </tr>
 <tr>
  <td colspan="2">&nbsp;</td>
 </tr>
 <tr>
  <td>
  <table style="position:relative; left:80px;">
  <tr>
  <td width="150"><b>NIK</b></td>
  <td>: <input type="text" maxlength="10" readonly="" value="<?=$nik?>" style="font-weight:bold;" class="text" name="nik"/> <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Status Karyawan</td>
  <td>: 
  <select name="status_karyawan" style="width:300px;" >
	<option value="">--Pilih--</option>
	<?
		$sqlS = mssql_query("SELECT * FROM VStatusKaryawan",$conn);
		while($rowS = mssql_fetch_array($sqlS)){
			echo"<option value='$rowS[kode]'";
			if($op == "edit"){
				if($rkarptsi[stat_kar1] == $rowS[kode]){
					echo" selected";
				}
			}									
			echo">$rowS[Nama]</option>";
		}
	?>
  </select> <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Status Kerja</td>
  <td>: 
  <select name="status_kerja" style="width:200px;">
   <option value="">--Pilih--</option>
	<?
		$sqlSK = mssql_query("SELECT * FROM VStatusKerja",$conn);
		while($rowSK = mssql_fetch_array($sqlSK)){
			echo"<option value='$rowSK[kode]'";
			if($op == "edit"){
				if($row[stat_kar] == $rowSK[kode]){
					echo" selected";
				}
			}						
			echo">$rowSK[Nama]</option>";
		}
	?>
  </select> <span class="required">*</span></td>
 </tr>
 <!--<tr>
  <td>Cara Kerja</td>
  <td>: 
  <select name="cara_kerja">
   <option value="">--Pilih--</option>
   <option value="1">AAAAAA</option>
   <option value="1">BBBBBB</option>
  </select> <span class="required">*</span></td>
 </tr>-->
 <tr>
  <td>Jabatan</td>
  <td>: 
  <select name="jabatan" style="width: 200px;" >
   <option value="">--Pilih--</option>
	<?
		$sqlJ = mssql_query("SELECT * FROM MstJabatan ORDER BY jabatan",$conn);
		while($rowJ = mssql_fetch_array($sqlJ)){
			echo"<option value='$rowJ[kode]'";
			if($op == "edit"){
				if($rkarptsi[jabatan1] == $rowJ[kode]){
					echo" selected";
				}
			}						
			echo">$rowJ[jabatan]</option>";
		}
	?>
  </select> <span class="required">*</span></td>
 </tr>
 <!--
 <tr>
  <td>Selesai Jabatan</td>
  <td>: <input type="text" maxlength="10" value="<?=$row[tamat_jabatan]?>" class="text" name="tamat_jabatan" size="11"/> <span class="required">*</span> <a href="javascript:calA.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a>
 </tr>
 -->
 <tr>
  <td>Golongan</td>
  <td>: 
  <select name="golongan" >
   <option value="">--Pilih--</option>
	<?
		for($r=1;$r<=15;$r++){
			echo"<option value='$r'";
			if($rkarptsi[gol1] == $r){
				echo" selected";
			}
			echo">$r</option>";
		}
	?>
  </select> <span class="required">*</span>
  </td>
 </tr>
 <!--
 <tr>
  <td>Selesai Golongan</td>
  <td>: <input type="text" maxlength="10" size="11" class="text" value="<?=$row[tamat_golongan]?>" name="tamat_golongan"/> <span class="required">*</span> <a href="javascript:calB.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a> 
  <span class="InfoForm">Format: dd/mm/yyyy</span>
  </td>
 </tr>
 -->
 <tr>
  <td>Fungsi</td>
  <td>: 
  <select name="fungsi" style="width:200px;" >
   <option value="">--Pilih--</option>
   <?
   		$k = mssql_query("SELECT * FROM MstFungsional ORDER BY nama",$conn);
		while($rk = mssql_fetch_array($k)){
			echo"<option value='$rk[kode]'";
			if($op == "edit"){
				if($rkarptsi[fungsi1] == $rk[kode]){
					echo" selected";
				}
			}			
			echo">$rk[nama]</option>";
		}
   ?>
  </select>
  <span class="required">*</span>
  </td>
 </tr>
 <tr>
  <td>Unit Kerja</td>
  <td>: 
  <select name="kode_so" style="width:400px;" >
  <option value="">--Pilih--</option>
   <?
   		$k_so = mssql_query("SELECT * FROM MstSO ORDER BY kode_so ASC",$conn);
		while($r_so = mssql_fetch_array($k_so)){
			echo"<option value='$r_so[kode_so]'";
			if($op == "edit"){
				if($rkarptsi[kode_so1] == $r_so[kode_so]){
					echo" selected";
				}
			}
			echo">$r_so[AreaCode] - $r_so[uraian]</option>";
		}
   ?>
  </select>
  <span class="required">*</span>
  </td>
 </tr>
 <tr>
  <td>Tanggal Masuk</td>
  <td align="left">: <input type="text" maxlength="10" size="11" class="text" value="<?=$row[TglMasuk]?>" name="tgl_masuk"/> <span class="required">*</span> <a href="javascript:calC.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a> 
  </td>
 </tr>
 <tr>
  <td>Tanggal Keluar</td>
  <td>: <input type="text" maxlength="10" size="11" class="text" value="<?=$row[TglKeluar]?>" name="tgl_keluar"/> <span class="required">*</span> <a href="javascript:calD.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a> 
  </td>
 </tr>
 <tr>
  <td>Tanggal Menikah</td>
  <td>: <input type="text" maxlength="10" size="11" class="text" value="<?=$row[TglNikah]?>" name="tgl_nikah"/> <span class="required">*</span> <a href="javascript:calE.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a> 
  </td>
 </tr>
 <tr>
  <td>&nbsp;</td>
  <td align="left"><br /><br />
  <input type="hidden" name="cat" value="emp_status" />
  <input type="reset" value="Clear" class="button"/><input type="button" value="<?=$Vbutton?>" class="button" onClick="Validate();" />
  <br /><br />
  </td>
 </tr>
</table>
</form>
<script type="text/javascript">
//<![CDATA[

var f = document.forms[0];
/*MaskInput(f.elements[0], "(99)9999-9999");
MaskInput(f.elements[1], "99/99/9999");
MaskInput(f.elements[2], "Cc99-*C");
MaskInput(f.elements[3], "E^abc");
MaskInput(f.elements[4], "O^abc");
MaskInput(f.elements[5], "C^");
MaskInput(f.elements[6], "C^ ");
MaskInput(f.elements[7], "9^abc");
*/
MaskInput(f.tamat_jabatan,"99/99/9999");
MaskInput(f.tamat_golongan,"99/99/9999");
MaskInput(f.tgl_masuk,"99/99/9999");
MaskInput(f.tgl_keluar,"99/99/9999");
MaskInput(f.tgl_nikah,"99/99/9999");

//]]>
</script>
<script type="text/javascript">
// script untuk popup calendar
/*
	var calA = new calendar1(document.forms['FEmployee'].elements['tamat_jabatan']);
	calA.year_scroll = true;
	calA.time_comp = false;
	
	var calB = new calendar1(document.forms['FEmployee'].elements['tamat_golongan']);
	calB.year_scroll = true;
	calB.time_comp = false;
*/
	var calC = new calendar1(document.forms['FEmployee'].elements['tgl_masuk']);
	calC.year_scroll = true;
	calC.time_comp = false;
	
	var calD = new calendar1(document.forms['FEmployee'].elements['tgl_keluar']);
	calD.year_scroll = true;
	calD.time_comp = false;

	var calE = new calendar1(document.forms['FEmployee'].elements['tgl_nikah']);
	calE.year_scroll = true;
	calE.time_comp = false;
	
</script>

</td>
</tr>
<tr>
 <td colspan="2" style="border:none;"><? include("../footer.php"); ?></td>
</tr>
</table>
</body>
</html>
